<?php

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 * Description of AppTypeService
 *
 * @author Administrator
 */
//import('@.service.TypeService');

class AppTypeService {

    function insert($appType) {
        
    }

    /**
     * 添加数据
     * @param type $appId
     * @param type $typeNameList 
     */
    function insertAllByTypeName($appId, $typeNameList) {
        $typeService = new TypeService();

        $typeIdList = $typeService->getTypeIdByNames($typeNameList);

        $appTypeTable = D('app_type');

        $data = array();
        foreach ($typeIdList as $tId) {
            array_push($data, array('app_id' => $appId, 'type_id' => $tId += 0));
        }
        $appTypeTable->addAll($data);
    }

    /**
     *  添加数据
     * @param type $appId
     * @param type $typeIdList 
     */
    function insertAllByTypeId($appId, $typeIdList) {
        $appTypeTable = D('app_type');

        $data = array();
        foreach ($typeIdList as $tId) {
            array_push($data, array('app_id' => $appId, 'type_id' => $tId));
        }
        $appTypeTable->addAll($data);
    }

    /**
     *  删除App
     * @param type $appId
     */
    function deleteByAppId($appId) {
        $appTypeTable = D('app_type');

        $lastId = $appTypeTable->where(array('app_id' => $appId))->delete();

        return $lastId;
    }

    /**
     * 删除
     * @param type $appIdList
     * @return type 
     */
    function deleteByAppIdList($appIdList) {
        $appTypeTable = D('app_type');

        $where['app_id'] = array('in', $appIdList);
        $lastId = $appTypeTable->where($where)->delete();

        return $lastId;
    }

    function listTypeIdByAppId($appId) {
        $appTypeTable = D('app_type');

        return $appTypeTable->where(array('app_id' => $appId))->field('type_id')->select();
    }

}

?>
